package com.hckjsec.system.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.system.domain.SysPartyBuilding;
import com.hckjsec.system.service.ISysPartyBuildingService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 党建Controller
 * 
 * @author cyt
 * @date 2021-10-12
 */
@RestController
@RequestMapping("/system/building")
public class SysPartyBuildingController extends BaseController
{
    @Autowired
    private ISysPartyBuildingService sysPartyBuildingService;

    /**
     * 查询党建列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysPartyBuilding sysPartyBuilding)
    {
        startPage();
        List<SysPartyBuilding> list = sysPartyBuildingService.selectSysPartyBuildingList(sysPartyBuilding);
        return getDataTable(list);
    }

    /**
     * 导出党建列表
     */
    @Log(title = "党建", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysPartyBuilding sysPartyBuilding)
    {
        List<SysPartyBuilding> list = sysPartyBuildingService.selectSysPartyBuildingList(sysPartyBuilding);
        ExcelUtil<SysPartyBuilding> util = new ExcelUtil<SysPartyBuilding>(SysPartyBuilding.class);
        return util.exportExcel(list, "building");
    }

    /**
     * 获取党建详细信息
     */
    @GetMapping(value = "/{partyId}")
    public AjaxResult getInfo(@PathVariable("partyId") Long partyId)
    {
        return AjaxResult.success(sysPartyBuildingService.selectSysPartyBuildingById(partyId));
    }

    /**
     * 新增党建
     */
    @Log(title = "党建", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPartyBuilding sysPartyBuilding)
    {
        sysPartyBuilding.setDeptId(SecurityUtils.getDeptId());
        sysPartyBuilding.setOperator(SecurityUtils.getUserId());
        return toAjax(sysPartyBuildingService.insertSysPartyBuilding(sysPartyBuilding));
    }

    /**
     * 修改党建
     */
    @Log(title = "党建", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPartyBuilding sysPartyBuilding)
    {
        return toAjax(sysPartyBuildingService.updateSysPartyBuilding(sysPartyBuilding));
    }

    /**
     * 删除党建
     */
    @Log(title = "党建", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partyIds}")
    public AjaxResult remove(@PathVariable Long[] partyIds)
    {
        return toAjax(sysPartyBuildingService.deleteSysPartyBuildingByIds(partyIds));
    }
}
